<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header"><?php echo __('Property') ?></h1>
        </div>
        <div class="col-lg-12">
            <?php
                    echo $this->Form->create('BoostCake', array(
                        'inputDefaults' => array(
                            'div' => 'form-group',
                            'wrapInput' => false,
                            'class' => 'form-control',
                            'method' => 'post'
                        ),
                        'class' => 'well',
                        'enctype' => 'multipart/form-data'
                    ));
                    ?>
            <ul id="myTab" class="nav nav-tabs">
                <li class="active"><a href="#home" data-toggle="tab"><?php echo __('general') ?></a></li>
                
                <?php if($this->data['Property']['type'] != 3):?>
                <li class=""><a href="#profile" data-toggle="tab"><?php echo __('Values') ?></a></li>
                <?php endif;?>
            </ul>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade active in" id="home">
                    <p>
                    <fieldset>
                        <?php
                        echo $this->Form->input('PropertyLanguage.name', array(
                            'label' => __('Property Name'),
                            'type' => 'text',
                            'required' => false
                        ));
                        ?>
                            <?php
                            echo $this->Form->input('Property.type', array(
                                    'label' => false,
                                    'type' => 'hidden'
                            ));
                            /* echo $this->Form->input('Property.type', array(
                                'label' => __('Property Type'),
                                'type' => 'radio',
                                'options' => array('1' => __('Options'), '2' => __('Archive')),
                            )); */
                            ?>
                        <?php
                        echo $this->Form->input('Property.oder', array(
                            'label' => __('order'),
                            'type' => 'text',
                            'required' => false
                        ));
                        ?>
                        
                    </fieldset>
                </p>
                </div>
                <?php if($this->data['Property']['type'] != 3):?>
                <div class="tab-pane fade" id="profile">
                    <div id="container_value">
                        <?php $key = -1; ?>
                        <?php if(isset($this->data['PropertyValueLanguage'])):?>
                        <?php echo '</br>';?>
                        <?php foreach($this->data['PropertyValueLanguage'] as $key => $value ): ?>
                        <div class="group_value_property">
                            <a class="condition_remove glyphicon glyphicon-remove"></a>
                            <?php
                                echo $this->Form->input('PropertyValueLanguage.'.$key.'.value', array(
                                    'label' => false,
                                    'type' => 'text'
                                ));
                                if(isset($value['property_value_id'])){
                                    echo $this->Form->input('PropertyValueLanguage.'.$key.'.property_value_id', array(
                                        'label' => false,
                                        'type' => 'hidden'
                                    ));
                                }
                            ?>
                        </div>
                        <?php endforeach;?>
                        <?php endif;?>
                        <div class="form-group" ></div>
                        <div class="btn" id="add_value"><a class='glyphicon glyphicon-plus'></a></div>
                    </div>
                </div>
                <?php endif;?>
            </div>
            <?php
                        echo $this->Form->submit('Submit', array(
                            'div' => 'form-group',
                            'class' => 'btn btn-default'
                        ));
                        ?>
            <?php echo $this->Form->end(); ?>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
</div>
<!-- /#page-wrapper -->
<script>
            
    $(document).ready(function(){
        var key = <?php echo $key;?>;
        var html = '<div class="group_value_property">\n\
                        <a class="condition_remove glyphicon glyphicon-remove"></a>\n\
                            <input name="data[PropertyValueLanguage][key][value]" class="form-control" type="text">\n\
                    </div>';
        $("#add_value").on('click',function(){
           key = key+1;
           var add = html.replace(new RegExp("key", 'g'),key);
           $("#container_value .form-group").last().after(add);
        });
        $(document).on('click','.condition_remove',function(){
            var div_parent = $(this).parents('.group_value_property');
            var input_hideen = div_parent.find( 'input[type=hidden]');
            if(input_hideen.size() == 1){
                $.ajax({
                    url: '<?php echo $this->Html->url('/property/delete')?>',
                    data: {'id':input_hideen.val()},
                    type: 'post',
                    dataType: 'json',
                    success: function(data){
                        if(data.success){
                            div_parent.remove();
                        }
                    }
                });
                
            }else{
                div_parent.remove();
            }
                
	});
        
    });
</script>